﻿using Model;
using System.Collections.Generic;
using Utility;
using System.Linq;

namespace Service
{
    public class Sys_DeptService : DapperDbContext<Sys_Dept>
    {
        public readonly static Sys_DeptService Instances = new Sys_DeptService();

        public int QueryCustomCount(string where, object param = null)
        {
            return base.QueryCount(where, param);
        }
        public Sys_Dept GetEntity(int id)
        {
            return base.QueryFirstOrDefault(@"Status=@Status and Id = @Id ", new { Status = Status.normal, Id = id });
        }
        public List<Sys_Dept> QueryCustom(string where, object param = null)
        {
            return base.Query(where, param).ToList();
        }
        public List<Sys_Dept> GetListByIds(List<int> Ids)
        {
            List<Sys_Dept> list = new List<Sys_Dept>();
            for (int i = 0; i < Ids.Count; i += 2000)//插入数据
            {
                list.AddRange(base.Query(@" Id in @Ids", new { Ids = Ids.Skip(i).Take(2000).ToArray() }).ToList());
            }
            return list;
        }
        public int Add(int userId, Sys_Dept ent)
        {
            ent.Init();
            ent.Id = base.Add(ent);
            return ent.Id;
        }
        public int AddBatch(int userId, List<Sys_Dept> list)
        {
            foreach (var item in list)
            {
                item.Init();
            }
            return base.AddBatch(list);
        }
        public int Edit(int userId, Sys_Dept ent)
        {
            return base.Edit(ent);
        }
        public int EditBatch(int userId,Sys_Dept model,int [] ids)
        {
            return base.EditBatch( model, ids) ;
        }
        public int EditBatch(int userId, List<Sys_Dept> list)
        {
            return base.EditBatch(list);
        }
    }
}
